package au.id.weston.scott.Vincent;

// Copyright (c) 2009, Scott Weston <scott@weston.id.au>
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright notice,
//       this list of conditions and the following disclaimer in the documentation
//       and/or other materials provided with the distribution.
//     * Neither the name of Scott Weston nor the names of contributors may be
//       used to endorse or promote products derived from this software without
//       specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import android.app.Activity;
import android.content.ContentValues;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class addconnection extends Activity implements View.OnClickListener {

	private final static String TAG = "vincent/addconnection";
	public static final String PREFS_NAME = "VincentPrefsFile";
	
	// -------------------------------------------------------------------------------------------
	// -------------------------------------------------------------------------------------------
	// -------------------------------------------------------------------------------------------
	
	EditText mount;
	EditText username;
	EditText password;
	EditText server;
	EditText share;
	EditText directory;
	EditText dest;
	Button mStart;
	Button mStop;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "onCreate()");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.add);
        mount = (EditText) findViewById(R.id.editMount);
        username = (EditText) findViewById(R.id.editName);
        password = (EditText) findViewById(R.id.editPasswd);
        server = (EditText) findViewById(R.id.editServer);
        share = (EditText) findViewById(R.id.editShare);
        directory = (EditText) findViewById(R.id.editDirectory);
        dest = (EditText) findViewById(R.id.editDest);
        mStart = (Button) findViewById(R.id.buttonStart);
        mStop = (Button) findViewById(R.id.buttonStop);
        
        mStart.setOnClickListener(this);
        mStop.setOnClickListener(this);
    }

	
	public void onClick(View view) {
		if (view == mStart) {
			ContentValues values = new ContentValues();
			values.put("mount_name", mount.getText().toString());
			values.put("username", username.getText().toString());
			values.put("password", password.getText().toString());
			values.put("server", server.getText().toString());
			values.put("share", share.getText().toString());
			values.put("directory", directory.getText().toString());
			values.put("destination", dest.getText().toString());
			values.put("direction", 1);
			DatabaseHelper dbh = new DatabaseHelper(this);
			dbh.insertNewConnection(values);
			finish();
		} else if (view == mStop) {
			finish();
		}
	}
}
